package com.thymeleaf_demo.controller;

import com.thymeleaf_demo.entity.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {
    @GetMapping("/hello")
    public String hello(Model model){
        model.addAttribute("username","lhb");
        model.addAttribute("username1","<h1>lhb</h1>");
        model.addAttribute("sex",1);
        model.addAttribute("city","岳阳");

        UserInfo user1=new UserInfo(1,"李白","123");
        UserInfo user2=new UserInfo(2,"杜甫","123");
        List<UserInfo> users=new ArrayList<>();
        users.add(user1);
        users.add(user2);
        model.addAttribute("users",users);

        model.addAttribute("date",new Date());
        return "hello";
    }

    @GetMapping("/login")
    public String login(String username,String pass){
        System.out.println(username);
        System.out.println(pass);
        System.out.println("发送请求成功");
        return "hello";
    }
}